import { EditorApp } from "../EditorApp";

/**枚举类，因实际值是number，只能往后追加，不可往中间插入 */
// export enum enCommandType {
//   Add,
// }

/**这里用字符串枚举，更好，交互更友好，自解释，减少理解成本，只要字符串名命规范，即可保证唯一性 */
export enum enCommandType {
  Undefined = 'Undefined',
  Add = 'Add',
}

export abstract class Command {
  protected _editor: EditorApp;
  protected _type: enCommandType = enCommandType.Undefined;
  protected _id: number = -1;
  protected _name: string = '';
  protected _object: null = null;
  protected _updatable: boolean = false;

  constructor(editor: EditorApp) {
    this._editor = editor;
  }

  abstract execute(): void;
  abstract undo(): void;

  toJSON() {
		const output: any = {};
		output.type = this._type;
		output.id = this._id;
		output.name = this._name;
		return output;
	}

	fromJSON( json: any ) {
		this._type = json.type;
		this._id = json.id;
		this._name = json.name;
	}

}
